import requests
import json
import string
import random
import time

#测试数据（Vin码 一线进出单证）
data = {}
portReleaseVin_1 = {}

class request_test():
    global data1
    data1 = json.dumps(data)

    def post_requests(self, for_num):
        #测试环境
        token = ''
        url = ''

        for_num = for_num
        status = '1'
        self.consumDt_2 = []
        a = []

        while status == '1':
            # if for_num >= 3:
            #     print('+***+*+*+*+*+**++**+**++*+**+*+*+')
            #     break
            i = 0
            while i < for_num:
                consumDt_0 = {}
                vin_num = ''.join(random.sample(string.digits, 6))
                timenum = time.strftime('%Y%m%d')
                # print(timenum)
                # print('9999999999')
                vin = 'LRW'+timenum+vin_num
                a.append(vin)
                while vin in a:
                    vin_num = ''.join(random.sample(string.digits, 6))
                    vin = 'LRW' + timenum + vin_num
                a.append(vin)
                # print(vin)
                portReleaseVin_1.update({"vin": 'LRW'+timenum+vin_num})
                consumDt_0.update(portReleaseVin_1)
                self.consumDt_2.append(consumDt_0)
                i += 1

            data = data1.replace("portReleaseVin_1", json.dumps(self.consumDt_2))
            # print(self.consumDt_2)
            data = data.replace('"[', '[')
            data = data.replace(']"', ']')
            data = data.replace("dclQty_1", json.dumps(for_num))
            data = data.replace("exitQuantity_1", json.dumps(for_num))

            print("=================1===================")
            try:
                headers = {"orgId": "103240", "Content-Type": "application/json", "epToken": "%s" % token}
                response = requests.post(url=url, headers=headers, data=data)
                print("请求信息：\n %s \n%s \n%s" % (url, headers, data))
                print("********************************")
                try:
                    print("=================2===================")
                    status = response.json().get("status")
                    print(response.json())
                except Exception as E:
                    print("获取返回状态失败：%s" % E)
                    print("当前最大支持表体数：%s" % (for_num-1))
                    # return False, response, E
                try:
                    ass_value = response.json()
                except Exception as E:
                    print("当前最大支持表体数：%s" % (for_num-1))
                    # return False, response, E

                if status == "1" and response.json().get("note") == '修改成功！':
                    print(response.json().get("note"))
                elif 'token cather user fail' in str(ass_value):
                    print("当前最大支持表体数：%s" % (for_num-1))
                else:
                    # return False, ass_value, "请求错误"
                    print('++++++++++++++++++++++++++++++')
                    status = 0
                    print(ass_value)
                    print("当前最大支持表体数：%s" % (for_num-1))
            except Exception as E:
                print("当前最大支持表体数：%s" % (for_num-1))
                print(E)
                return False, E, "请求异常"
            for_num += 1
            print(for_num)


request_test().post_requests(1000)
